<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
import { Mutations, SaveName, RouteUrl } from "src/common/const";
import 'babel-polyfill';  //兼容性 ie 安卓版本 es语法编译成浏览器可以识别的语法
import { mapState, mapActions } from "vuex";
export default {
  computed: mapState({
    user: "user",
    initUrl: "initUrl",

    saveInsure: "saveInsure",
    abroadTravel: "abroadTravel",
    detailsStore: "detailsStore",
    isWeChar: "isWeChar",
    isInitData: "isInitData"
  }),
  name: "app",
  beforeMount() {
    //获取token
    this.$common.storeCommit(this, Mutations.SET_VAL_DATA, this);
    //版本控制用户刷新
    let version = "18.04.16.10";//每次升级请提高该版本号
    if (localStorage["version"] != version) {//不是最新版本号
      this.$common.storeCommit(this, Mutations.SET_OLD_VERSION, true);
    }
    localStorage["version"] = version;
    //用户初始化或保存到VUEX
    this.initIsLogin();
    //初始化险种信息
    this.$common.storeCommit(this, Mutations.QUERY_INIT_RISK_DATA, this);
    //初始化菜单信息
    this.$common.storeCommit(this, Mutations.QUERY_MENU_DATA, this);
  },
  methods: {
    //产品详情判断
    isGoUrlDetails() {
      //URI有无参数并跳转，否则到首页
      // let userCode = "";
      // if (this.user.isLogin) {
      //   userCode = this.user.userDto.userCode;
      // }

      // let parm = { _this: this, url: window.location.href, userCode: userCode };
      // if (parm.url.lastIndexOf("?") > 0 && parm.url.lastIndexOf("=") > 0) {
      //   if (parm.url.indexOf(RouteUrl.DETAILS) >= 0) {
      //     this.$common.storeCommit(this, Mutations.SHARE_URL_SET, parm);
      //     //路由到产品详情
      //     this.$common.goUrl(this, RouteUrl.DETAILS);
      //   } else {
      //     //解码URI--------------decodeURI不能完全解码,必须使用decodeURIComponent
      //     // let url = decodeURIComponent(parm.url);
      //     // //获取参数部分，系统连接（……?=67/P=），分享链接（?&=46/38/U=）
      //     // let parms = url.substring(url.lastIndexOf("?&="));
      //     // if (parms.lastIndexOf("=") > 0) {
      //     //   //截取参数到尾部多余参数，系统连接（67/P），分享链接（46/38/U）
      //     //   parms = parms.substring(parms.indexOf("=") + 1, parms.lastIndexOf("="));
      //     // }
      //     // let parameters = parms.split("/");
      //     // if (!isNaN(parseInt(parameters[0]))) {
      //     //   console.log("来自分享的参数：" + JSON.stringify(parameters));
      //     // }
      //   }
      // }
    },
    //登录信息初始化
    initIsLogin() {
      //=============================================================自营平台
      // let storeInfo = sessionStorage[SaveName.LOCAL_STORAGE_USER];
      let storeInfo = localStorage[SaveName.LOCAL_STORAGE_USER];
      if (this.$common.isNotEmpty(storeInfo)) {
        let userInfo = eval("(" + storeInfo + ")");
        let data = { _this: this, userInfo: userInfo }
        //保存USER_INFO信息
        this.$common.storeCommit(this, Mutations.SAVE_USER_INFO_INIT, data);
      }
    }
  },
  errorCaptured(errorMeg, routeThis, method) {
    // debugger
    // alert(errorMeg);
    // alert(routeThis);
    // alert(method);
    // console.log(this.$route.path);
    // this.$vux.alert.show({ content: this.$common.alertMsg("服务器出了一点小问题~", "red;") });
    this.$router.push({
      path: RouteUrl.INDEX
    });
  },
  mounted() {
    // this.$common.setUuid(this);
    this.$common.storeCommit(this, Mutations.SET_IS_WE_CHAR);
    this.isGoUrlDetails();
    sessionStorage["WECHAT_SHARE"] = "false";
    console.log(localStorage["version"]);
  }
};
</script>

<style lang="scss">
@import "~styles/common";
</style>

<style lang="less">
@import "~styles/theme.less";
@import "~vux/src/styles/reset.less";
#app {
  width: 100%;
  height: 100%; // max-width: 750px; // min-width: 750px;
}

// @font-face {
//   font-family: "楷体_GB2312";
//   src: url("~assets/font/楷体_GB2312.ttf");
// }
// @font-face {
//   font-family: "HYHanShiTiJ";
//   src: url("~assets/font/HYHanShiTiJ.ttf");
// }

body {
  background-color: #f0f0f0; // max-width: 750px;
  margin: 0 auto; // position: absolute;
  height: 100%;
  // font-family: PingFangSC-Regular, Verdana, Arial, "微软雅黑", "宋体";
  -webkit-text-size-adjust: 100% !important;
  text-size-adjust: 100% !important;
  -moz-text-size-adjust: 100% !important;
}

input {
  font-size: 14px;
}

* {
  margin: 0;
}
</style>
